package com.talkingdata.hadoop.guard.mapper;

import com.talkingdata.hadoop.guard.bean.DfsClusterState;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DfsClusterMapper {
    @Insert("insert into dfs_cluster_state (" +
            "service_id,is_safemode,is_security,active_namenode," +
            "capacity,capacity_byte_desc,total_blocks,total_files,percent_used," +
            "missing_blocks,under_replicated_blocks,num_live_datanodes,num_dead_datanodes," +
            "num_decom_live_datanodes,num_decom_dead_datanodes,version,timestamp) values (#{serviceId}," +
            "#{isSafemode},#{isSecurity},#{activeNamenode},#{capacity},#{capacityByteDesc},#{totalBlocks}," +
            "#{totalFiles},#{percentUsed},#{missingBlocks},#{underReplicatedBlocks},#{numLiveDatanodes}," +
            "#{numDeadDatanodes},#{numDecomLiveDatanodes},#{numDecomDeadDatanodes},#{version},#{timestamp})")
    int insertDfsCluster(DfsClusterState dfsClusterState);

    @Results({
            @Result(property = "serviceId",column = "service_id"),
            @Result(property = "isSafemode",column = "is_safemode"),
            @Result(property = "isSecurity",column = "is_security"),
            @Result(property = "activeNamenode",column = "active_namenode"),
            @Result(property = "capacityByteDesc",column = "capacity_byte_desc"),
            @Result(property = "totalBlocks",column = "total_blocks"),
            @Result(property = "totalFiles",column = "total_files"),
            @Result(property = "percentUsed",column = "percent_used"),
            @Result(property = "missingBlocks",column = "missing_blocks"),
            @Result(property = "underReplicatedBlocks",column = "under_replicated_blocks"),
            @Result(property = "numLiveDatanodes",column = "num_live_datanodes"),
            @Result(property = "numDeadDatanodes",column = "num_dead_datanodes"),
            @Result(property = "numDecomLiveDatanodes",column = "num_decom_live_datanodes"),
            @Result(property = "numDecomDeadDatanodes",column = "num_decom_dead_datanodes")
    })
    @Select("select * from dfs_cluster_state " +
            "where service_id=#{service_id} order by id DESC limit 1 ")
    DfsClusterState selectDfsClusterStateByServiceId(@Param("service_id") String service_id);
}
